package com.ruoyi.web.controller.system.wechat;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysWechat;
import com.ruoyi.system.service.ISysWechatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信公众号推送Controller
 * 
 * @author ruoyi
 * @date 2022-08-25
 */
@RestController
@RequestMapping("/system/wechat")
public class SysWechatController extends BaseController
{
    @Autowired
    private ISysWechatService sysWechatService;

    /**
     * 查询微信公众号推送列表
     */
    @PreAuthorize("@ss.hasPermi('system:wechat:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysWechat sysWechat)
    {
        startPage();
        List<SysWechat> list = sysWechatService.selectSysWechatList(sysWechat);
        return getDataTable(list);
    }

    /**
     * 导出微信公众号推送列表
     */
    @PreAuthorize("@ss.hasPermi('system:wechat:export')")
    @Log(title = "微信公众号推送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysWechat sysWechat)
    {
        List<SysWechat> list = sysWechatService.selectSysWechatList(sysWechat);
        ExcelUtil<SysWechat> util = new ExcelUtil<SysWechat>(SysWechat.class);
        util.exportExcel(response, list, "微信公众号推送数据");
    }

    /**
     * 获取微信公众号推送详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:wechat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysWechatService.selectSysWechatById(id));
    }

    /**
     * 新增微信公众号推送
     */
    @PreAuthorize("@ss.hasPermi('system:wechat:add')")
    @Log(title = "微信公众号推送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysWechat sysWechat)
    {
        return toAjax(sysWechatService.insertSysWechat(sysWechat));
    }

    /**
     * 修改微信公众号推送
     */
    @PreAuthorize("@ss.hasPermi('system:wechat:edit')")
    @Log(title = "微信公众号推送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysWechat sysWechat)
    {
        return toAjax(sysWechatService.updateSysWechat(sysWechat));
    }

    /**
     * 删除微信公众号推送
     */
    @PreAuthorize("@ss.hasPermi('system:wechat:remove')")
    @Log(title = "微信公众号推送", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysWechatService.deleteSysWechatByIds(ids));
    }
}
